<?php require_once('../Connections/sepolwan_connect.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
include "../txt/url.php";
include "../tambah/date.php";
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_sesi_member = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_sesi_member = $_SESSION['MM_Username'];
}
mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_sesi_member = sprintf("SELECT * FROM memberdb WHERE email = %s", GetSQLValueString($colname_sesi_member, "text"));
$sesi_member = mysql_query($query_sesi_member, $sepolwan_connect) or die(mysql_error());
$row_sesi_member = mysql_fetch_assoc($sesi_member);
$totalRows_sesi_member = mysql_num_rows($sesi_member);

mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_chat = "SELECT DISTINCT * FROM chat WHERE ke = '".$row_sesi_member['nama_user']."' AND stat = 'ur' ORDER BY id DESC ";
$chat = mysql_query($query_chat, $sepolwan_connect) or die(mysql_error());
$row_chat = mysql_fetch_assoc($chat);
$totalRows_chat = mysql_num_rows($chat);

mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_ikut_me = "SELECT * FROM ikut WHERE dari = '".$row_sesi_member['id']."' ORDER BY id DESC";
$ikut_me = mysql_query($query_ikut_me, $sepolwan_connect) or die(mysql_error());
$row_ikut_me = mysql_fetch_assoc($ikut_me);
$totalRows_ikut_me = mysql_num_rows($ikut_me);
?>
<?php if ($totalRows_sesi_member > 0) { // Show if recordset not empty ?>
<?php if ($totalRows_chat > 0) { // Show if recordset not empty ?>
<div style="padding:10px; background:#000; color:#FFF">Pesan Baru</div>
  <?php do { 
if($row_sesi_member['nama_user']==$row_chat['dari'])
$ini=$row_chat['ke'];
if($row_sesi_member['nama_user']==$row_chat['ke'])
$ini=$row_chat['dari'];
$colname_member = "-1";
if (isset($ini)) {
  $colname_member = $ini;
}
mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_member = sprintf("SELECT * FROM memberdb WHERE nama_user = %s", GetSQLValueString($colname_member, "text"));
$member = mysql_query($query_member, $sepolwan_connect) or die(mysql_error());
$row_member = mysql_fetch_assoc($member);
$totalRows_member = mysql_num_rows($member);
?>
  <div id="chat2"><a href="<?php echo $row_member['nama_user']; ?>.html"><div style="width:50px; height:50px; overflow:hidden; border:1px solid #CCC; float:left"><img src="<?php echo $base.'images/member/ava/'.md5($row_member['id']).'_small.jpg' ?>" /></div>
    <div style="margin-left:60px; min-height:50px"><strong><?php echo $row_member['full_name']; ?></strong><br />
<font size="-2"><?php echo $row_chat['pesan']; ?></font><br />
<font size="-4" color="#999999"><?php echo tgl_indo($row_chat['waktu']), substr($row_chat['waktu'], 10, 6), " WIB"; ?></font></div></a></div>
  <?php 
  mysql_free_result($member);
  } while ($row_chat = mysql_fetch_assoc($chat)); ?>
  <?php } // Show if recordset not empty ?>
  
<?php } // Show if recordset not empty 
else { echo "<a href='".$base."'>klik</a>"; }?>
<?php
mysql_free_result($sesi_member);

mysql_free_result($chat);

mysql_free_result($ikut_me);
?>
